package net.lab1024.sa.admin.module.business.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.lab1024.sa.admin.module.business.erp.dao.WageaDao;
import net.lab1024.sa.admin.module.business.erp.domain.entity.WageaEntity;
import net.lab1024.sa.admin.module.business.erp.domain.form.add.WageaAddForm;
import net.lab1024.sa.admin.module.business.erp.domain.form.query.WageaQueryForm;
import net.lab1024.sa.admin.module.business.erp.domain.form.update.WageaUpdateForm;
import net.lab1024.sa.admin.module.business.erp.domain.vo.WageaVO;
import net.lab1024.sa.admin.module.business.erp.service.WageaService;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.ValidateList;
import net.lab1024.sa.base.common.util.SmartExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 工资明细 Controller
 *
 * @Author AKITA
 * @Date 2025-04-19 13:25:43
 * @Copyright AKITA
 */

@RestController
@Tag(name = "工资明细")
public class WageaController {

    @Resource
    private WageaService wageaService;
    @Autowired
    private WageaDao wageaDao;

    @Operation(summary = "分页查询 @author AKITA")
    @PostMapping("/wagea/queryPage")

    public ResponseDTO<PageResult<WageaVO>> queryPage(@RequestBody @Valid WageaQueryForm queryForm) {
        return ResponseDTO.ok(wageaService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author AKITA")
    @PostMapping("/wagea/add")
    public ResponseDTO<String> add(@RequestBody @Valid WageaAddForm addForm) {
        return wageaService.add(addForm);
    }



    @PostMapping("/wagea/deleteLine")
    public ResponseDTO<String> deleteLine(@RequestBody @Valid WageaAddForm addForm) {
        return wageaService.deleteLine(addForm);
    }


    @Operation(summary = "更新 @author AKITA")
    @PostMapping("/wagea/update")

    public ResponseDTO<String> update(@RequestBody @Valid WageaUpdateForm updateForm) {
        return wageaService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author AKITA")
    @PostMapping("/wagea/batchDelete")

    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return wageaService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author AKITA")
    @GetMapping("/wagea/delete/{docEntry}")

    public ResponseDTO<String> batchDelete(@PathVariable Long docEntry) {
        return wageaService.delete(docEntry);
    }

    @Operation(summary = "导出 @author 卓大")
    @GetMapping("/wagea/export/{docEntry}")
    public void export(HttpServletResponse response, @PathVariable Long docEntry) throws IOException {
        List<WageaEntity> list = wageaDao.selectList(new LambdaQueryWrapper<WageaEntity>().eq(WageaEntity::getDocEntry, docEntry));

        SmartExcelUtil.exportExcel(response, "工资细表.xlsx", "商品", WageaEntity.class, list);
    }

}
